; Procedure to find the smallest word in array A[1..Count]
; Parameters:  (1)  address of array A
;              (2)  value of Count (word)
;              (3)  address of Min (destination for smallest)
; No register is changed.  Flags are unchanged
Minimum PROC   NEAR32
        push   ebp           ; establish stack frame
        mov    ebp,esp
        pushad               ; save all registers   
        pushf                ; save flags

        mov    ebx,[ebp+14]  ; get address of array A
        mov    ecx, 0        ; ensure high order 0s in ECX
        mov    cx,[ebp+12]   ; get value of Count
        mov    eax,7fffffffh ; smallest so far (MaxInt)
        jecxz  endForCount   ; exit when no elements to check
forCount:
        cmp    [ebx],eax     ; element < smallest so far ?
        jnl    endIfLess     ; exit if not
        mov    eax,[ebx]     ; new smallest
endIfLess: 
        add    ebx,4         ; address of next array element
        loop   forCount      ; iterate
endForCount:
        mov    ebx,[ebp+8]   ; get address of Min
        mov    [ebx],eax     ; move smallest to Min
        popf                 ; restore flags
        popad                ; restore registers
        pop    ebp           ; restore EBP
        ret                  ; return
Minimum ENDP

